package com.loanapp.server.user.provider.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.loanapp.base.common.exception.BusinessException;
import com.loanapp.server.user.api.user.api.UserApi;
import com.loanapp.server.user.api.user.entity.User;
import com.loanapp.server.user.api.user.query.UserQuery;
import com.loanapp.server.user.provider.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("user")
public class UserController implements UserApi{

    @Autowired
    private UserService userService;

    @PostMapping
    public User selectById(@RequestParam Long id) throws BusinessException {
        return userService.selectByPk(id);
    }

    @PostMapping
    public User selectByQuery(@RequestBody UserQuery query) throws BusinessException {
        return userService.selectByModel(query);
    }

    @PostMapping
    public Boolean del(@RequestParam Long id) throws BusinessException {
        return userService.DeleteByPk(id);
    }

    @PostMapping
    public Boolean update(@RequestBody User user) throws BusinessException {
        return userService.Update(user);
    }

    @Override
    public Page<User> getListPage(@RequestBody UserQuery userQuery) throws BusinessException {
        return null;
    }

    @PostMapping
    public User getUser(@RequestParam Long id) throws BusinessException {
        return selectById(id);
    }

    @PostMapping
    public Long insert(@RequestBody User user) throws BusinessException {
        return userService.Insert(user);
    }
}
